package tianwang.stat;

import java.util.HashSet;
import java.util.List;

import tianwang.model.AticleModel;
import tianwang.services.collect.CollectResult;
import tianwang.services.collect.Collecter;

public class WordsVariationCollecter implements Collecter<CollectResult> {

	@Override
	public CollectResult collect(Object material) throws Exception {
		AticleModel model = (AticleModel) material;
		List<String> words = model.getEntityWords();
		
		int totalWords = words.size();
		HashSet<String> set = new HashSet<String>();
		for ( int i=0; i<words.size(); i++){
			
			String word = words.get(i);
			set.add(word);
		}
		
		final int wordVariation = set.size()*100/totalWords;
		return new CollectResult(){
			public Object pump(){
				return wordVariation;
			}
		};
	}

}
